package br.com.async.agilequiz.controller.user;

import java.security.NoSuchAlgorithmException;

import br.com.async.agilequiz.database.DatabaseManager;
import br.com.async.agilequiz.encrypt.Encrypt;

/**
 * @author rondymesquita
 * Essa classe 
 */
public class UserController {
	
	
	public void create(User user) throws NoSuchAlgorithmException{
		UserDao dao = new UserDao(DatabaseManager.getInstance().getHelper());
		User u = new User();
		
		/*
		 * Encriptando a senha
		 */
		Encrypt encrypt = new Encrypt();
		u.setUsername(user.getUsername());
		u.setPassword(encrypt.md5(user.getPassword()+user.getUsername()));
		
		dao.create(u);
		//System.out.println("User created with sucess!");
	}
	
	public User getUser(String username) {
		UserDao dao = new UserDao(DatabaseManager.getInstance().getHelper());
		return dao.getUserByName(username);
	}
	
	public boolean doLogin(String username, String password) throws NoSuchAlgorithmException{
//		UserDao dao = new UserDao(DatabaseManager.getInstance().getHelper());
//		Encrypt encrypt = new Encrypt();
//		String p = encrypt.md5(password+username);
//		
//		if(dao.getUser(username, p))
			return true;
		
//			return false;
		
	}

}
